package com.cn.yz.springboot.rabbitmq.receiver;

import java.io.ByteArrayInputStream;
import java.io.ObjectInputStream;
import java.io.UnsupportedEncodingException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Service;

import com.cn.yz.springboot.model.SysUser;
import com.cn.yz.springboot.util.ObjTransUtils;

@Service
public class WeixinReceiver implements BaseReceiver{

	Logger logger = LoggerFactory.getLogger(WeixinReceiver.class);
	
	@Override
	@RabbitListener(queues = "wx-spring-boot")
	public void receiveMessage(Message message){
		try {
			logger.info("推送微信 body====>"+message.getBody());
			SysUser user = ObjTransUtils.byteArrayToObject(SysUser.class, message.getBody());
			logger.info("推送微信 body====>"+user.getAccount());
		} catch (Exception ex){
			ex.printStackTrace();
		}
		/*try {
			logger.info("推送微信 body====>"+new String(message.getBody(), "UTF8"));
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}*/
		logger.info("推送微信 body====>"+message.getBody());
		logger.info("推送微信====>"+message.getMessageProperties().getConsumerQueue());
	}

}
